<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <script type="text/javascript" src="lib/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="lib/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="lib/css/bootstrap.min.css">
</head>
<body style="background: #eeeeee">
<div class="container" style="margin-top: 200px">

    <div class="col-xs-4 col-xs-offset-4">

        <form action="login" method="post" class="form-signin">

            <div class="form-group">
                <label></label>
                <input type="text" name="phone" id="phone"
                       class="form-control" placeholder="请输入手机号">
            </div>
            <div class="form-group">
                <label></label>
                <input type="text" name="userName" id="name"
                       class="form-control" placeholder="请输入姓名">
            </div>
            <div class="form-group">
                <label></label>
                <input type="text" name="userName" id="userName"
                       class="form-control" placeholder="请输入用户名">
            </div>
            <div class="form-group">
                <label></label>
                <input type="password" name="pwd" id="pwd" class="form-control" placeholder="请输入密码">
            </div>
            <div class="form-group">
                <label></label>
                <input type="password" name="repwd" id="repwd" class="form-control" placeholder="请确认密码">
            </div>

            <div class="form-group">
                <label></label>
                <button id="regist" type="button" class="btn btn-info" style="width: 100%">注册</button>
            </div>
            <a href="login.html">登录</a>


        </form>
    </div>

</div>
</body>
</html>
<script type="application/javascript">
    $("#regist").click(function(event) {
        if ($("#pwd").val() == $("#repwd").val()){
            $.ajax({
                url: '/libms/regist',
                type: 'post',
                dataType: 'json',
                data: {
                    pwd: $("#pwd").val(),
                    phone: $("#phone").val(),
                    name: $("#name").val(),
                    uname:$('#userName').val()
                },
            })
                .done(function(e) {
                    console.log("success");
                    if (e.code == 1){
                        window.location.href = "login.html"
                    } else {
                        alert("注册失败")

                    }
                })
                .fail(function(e) {
                    alert("网络错误，请稍后再试")
                })
                .always(function() {
                    console.log("complete");
                });
        } else {
            alert("两次密码不一致")
        }

    });
</script>